<?php
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");


if(($db_msg=cron_initialize()) !== true){
	print_r("Connection error");
}else{
	$r = mysql_query("SELECT * FROM gg_users WHERE swallet>0");
    $datetime = date('Y-m-d H:i:s');
    while($user = mysql_fetch_assoc($r))
	{
        $twallet = $user['twallet'] + $user['swallet'];
        mysql_query("insert into gg_member_twallet_record (uid,type,amount,bal,descr,cdate) values (".$user["id"].",'credit',".$user['swallet'].",".$twallet.",'Convert from SSF','".$datetime."')");
        mysql_query("insert into gg_member_swallet_record (uid,type,amount,bal,descr,cdate) values (".$user["id"].",'debit',".$user['swallet'].",0,'Convert to AP','".$datetime."')");
        mysql_query("update gg_users set swallet=0,twallet=".$twallet." where id=".$user["id"]);
    }

    print_r('Done');
}
exit;		
?>